package com.study.score.service.impl;

import java.util.List;

import com.study.common.utils.SecurityUtils;
import com.study.course.domain.SysCourse;
import com.study.course.mapper.SysCourseMapper;
import com.study.student.domain.SysStudent;
import com.study.student.mapper.SysStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.study.score.mapper.SysScoreMapper;
import com.study.score.domain.SysScore;
import com.study.score.service.ISysScoreService;

/**
 * 成绩查询Service业务层处理
 * 
 * @author rose
 * @date 2025-05-21
 */
@Service
public class SysScoreServiceImpl implements ISysScoreService 
{
    @Autowired
    private SysScoreMapper sysScoreMapper;

    @Autowired
    private SysCourseMapper sysCourseMapper;

    @Autowired
    private SysStudentMapper studentMapper;
    /**
     * 查询成绩查询
     * 
     * @param studentId 成绩查询主键
     * @return 成绩查询
     */
    @Override
    public SysScore selectSysScoreByStudentId(String studentId)
    {
        return sysScoreMapper.selectSysScoreByStudentId(studentId);
    }

    /**
     * 查询成绩查询列表
     * 
     * @param sysScore 成绩查询
     * @return 成绩查询
     */
    @Override
    public List<SysScore> selectSysScoreList(SysScore sysScore) {
        Long currentUserId = SecurityUtils.getUserId();

        // 判断是否是学生
        SysStudent student = studentMapper.selectStudentByUserId(currentUserId);
        System.out.println("查询到的学生对象: " + student);
        if (student != null) {
            sysScore.setStudentId(student.getStudentId());
            System.out.println("设置 studentId: " + sysScore.getStudentId()); // 打印确认
        }
        return sysScoreMapper.selectSysScoreList(sysScore);
    }


    /**
     * 新增成绩查询
     * 
     * @param sysScore 成绩查询
     * @return 结果
     */
    @Override
    public int insertSysScore(SysScore sysScore)
    {
        return sysScoreMapper.insertSysScore(sysScore);
    }

    /**
     * 修改成绩查询
     * 
     * @param sysScore 成绩查询
     * @return 结果
     */
    @Override
    public int updateSysScore(SysScore sysScore)
    {
        return sysScoreMapper.updateSysScore(sysScore);
    }

    /**
     * 批量删除成绩查询
     * 
     * @param studentIds 需要删除的成绩查询主键
     * @return 结果
     */
    @Override
    public int deleteSysScoreByStudentIds(String[] studentIds)
    {
        return sysScoreMapper.deleteSysScoreByStudentIds(studentIds);
    }

    /**
     * 删除成绩查询信息
     * 
     * @param studentId 成绩查询主键
     * @return 结果
     */
    @Override
    public int deleteSysScoreByStudentId(String studentId)
    {
        return sysScoreMapper.deleteSysScoreByStudentId(studentId);
    }

    @Override
    public List<SysStudent> selectSysStudentList() {
        List<SysStudent> sysStudent = sysCourseMapper.selectStudentList();
        return sysStudent;
    }

    @Override
    public List<SysCourse> selectSysCourseList(SysCourse sysCourse) {
        return sysCourseMapper.selectSysCourseList(sysCourse);
    }

}
